const {
  http
} = require("../../utils/apiutils");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    minDate: new Date().getTime(),
    maxDate: new Date().getTime(),
    gwInfo: {},
    time: "",
    dataList: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  selectTimes: function (e) {
    console.log("----------", e);
    let times = e.detail;
    var y = times.getFullYear();
    var m = times.getMonth();
    var d = times.getDate();
    this.data.time = y + "-" + this.add0(m + 1) + "-" + this.add0(d)
    this.getclockInList();

  },
  add0(m) {
    return m < 10 ? '0' + m : m
  },
  get3MonthBefor: function () {
    var year, month, date, hms;
    var currDate = new Date();
    year = currDate.getFullYear();
    month = currDate.getMonth() + 1;
    date = currDate.getDate();
    switch (month) {
      case 1:
      case 2:
      case 3:
        month += 9;
        year--;
        break;
      default:
        month -= 3;
        break;
    }
    month = (month < 10) ? ('0' + month) : month;
    return {
      year,
      month,
      date
    };
  },
  onLoad: function (options) {
    var today = new Date();
    var y = today.getFullYear();
    var m = today.getMonth();
    var d = today.getDate();
    let min = this.get3MonthBefor()
    this.setData({
      minDate: new Date(min.year, min.month, 1).getTime(),
      maxDate: new Date(y, m, d).getTime(),
    })
    this.data.time = y + "-" + this.add0(m + 1) + "-" + this.add0(d)
    let info = JSON.parse(decodeURIComponent(options.info));
    this.setData({
      gwInfo: info,
    })
    this.getclockInList()

  },

  getclockInList: function () {
    var data = {
      id: this.data.gwInfo.id,
      time: this.data.time,
    }
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    http.getclockInList1(data,
      function (res) {
        wx.hideLoading()
        console.log("------打卡信息--", res);
        if (res.code == 0) {
          let arr = res.data;
          arr.forEach(element => {
            if (element.imagePath != "") {
              element.imgList = element.imagePath.split(",")
            } else {
              element.imgList = []
            }
          });
          console.log("------------", arr);
          that.setData({
            dataList: arr,
          })
        } else {
          wx.showToast({
            title: res.message,
            icon: "none",
          })
        }


      },
      function (err) {
        wx.hideLoading()
      })
    console.log("----------", data);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var shareObj = {
      title: "分享岗位", // 默认是小程序的名称(可以写slogan等)
      path: getApp().globalData.userInfo.inviteCode?'/pages/index/index?code='+getApp().globalData.userInfo.inviteCode:'/pages/index/index', // 
      imageUrl: '',
      success: function (res) {
        // 转发成功之后的回调
        if (res.errMsg == 'shareAppMessage:ok') {
        }
      }
    }
    console.log("------------", shareObj);
    // 返回shareObj
    return shareObj;
  }
})